<template>
  <div class="export_wrapper">
    <div id="pagebox">
      <div class="talent_detail" style="text-align:left;">
        <div class="exprot_his">
          <div class="title fs16_bold">
            <a v-on:click="history_open();" class="history_btn">导出历史</a>
            <span>导出</span>
          </div>
          <!--/lang_list-->
        </div>
        <!--/language-->
        <div class="info">
          <span class="sp-1" :title="info.batchName">
            <var>批次名称</var>：{{info.batchName}}</span>
          <span>
            <var>批次文件</var>：{{info.fileNum}}
            <var>个</var>
          </span>
          <span>
            <var>已标注文件</var>：{{info.markNum}}
            <var>个</var>
          </span>
          <span>
            <var>已检查文件</var>：{{info.checkNum}}
            <var>个</var>
          </span>
          <span>
            <var>已质检文件</var>：{{info.authNum}}
            <var>个</var>
          </span>
        </div>

        <div class="typelist">
          <div class="selectBox">
            <div id="baseSetting">
              <ExportSet ref="exportSet" @dateChange="dateChange" />
            </div>
          </div>
        </div>

        <div class="export_btn">
          <a class="yes" v-on:click="submit();">导出到本地</a>
          <a class="yes" v-on:click="exporto();">导出到研发网</a>
        </div>
      </div>
      <div id="history">
        <div class="layer" v-show="historyBox">
          <div class="show_pop bdradius history">
            <div class="poptitle">
              <i v-on:click="history_close();"></i>
              <span class="fs14_bold">导出历史</span>
            </div>
            <div class="table">
              <table width="100%">
                <thead>
                  <tr>
                    <td>导出人</td>
                    <td>导出数据</td>
                    <td>导出类型</td>
                    <td>操作时间</td>
                    <td>状态</td>
                    <td>操作</td>
                  </tr>
                </thead>
                <tbody v-for="(item, ind) in historyList" :key="ind">
                  <tr>
                    <td>{{item.operator}}</td>
                    <td v-if="item.operateData == '-1'">全部</td>
                    <td v-else>{{item.operateData | filterData}}</td>
                    <td>{{item.operateType | filterType}}</td>
                    <td>{{item.operateTime | filterTime}}</td>
                    <td>{{item.statu | filterStatus}}</td>
                    <td>
                      <a v-on:click="download(item._id);" v-if="item.operator != 'ccr_datawell@qq.com'">下载</a>
                      <span v-else>--</span>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            <!-- <div class="pagesize" id="pagesize"></div> -->
            <Page size="small" v-show="historyList && historyList.length > 0" :total="pagination.total" show-sizer :page-size="pagination.pageSize" :current="pagination.currPage" :page-size-opts="[10, 20, 30]" @on-change="handleSizeChange" @on-page-size-change="handleCurrentChange" class="page_nav"></Page>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Lang } from '@/assets/js/ass_config'
import ExportSet from '@/components/export/ExportSet'
export default {
  name: 'Export',
  data() {
    return {
      groupId: '',
      // locality: false, 
      historyBox: false,
      info: {
        taskId: "",
        batchId: "",
        batchName: "",
        fileNum: "",
        markNum: "",
        checkNum: "",
        authNum: "",
        startTime: "",
        endTime: ""
      },
      historyList: [],
      urlArgs: {}, // url参数
      pagination: { // 分页配置
        currPage: 1,
        pageSize: 10,
        total: 0,
        handleSizeChange: this.handleSizeChange,
        handleCurrentChange: this.handleCurrentChange
      },
    }
  },
  created() {
    document.title = '导出结果'
    this.urlArgs = this.Utils.getQueryStringArgs()
    this.groupId = this.urlArgs.groupId;
    // var permissions = manageIdentity();
    // if (permissions.indexOf('batch_export_local') >= 0) {
    //   this.locality = true;
    // } else {
    //   this.locality = false;
    // }
    // 
    this.loadPage();
  },
  mounted() {
  },
  methods: {
    dateChange(timerArr) {
      this.info.startTime = timerArr[0]
      this.info.endTime = timerArr[1]
    },
    async loadPage() {
      //默认今天
      var nowTime = this.Utils.getNow();
      let id = this.urlArgs.id; //上面获取到的id是错误的
      let batchInfo = await this.ass_api.batchInfo({ batchId: id })
      if (!batchInfo) return;
      this.info = batchInfo[0];
      this.info.startTime = "";
      this.info.endTime = nowTime;
      this.info.markNum = (this.info.progress.mark == null || this.info.progress.mark['done'] == null) ? "0" : this.info.progress.mark['done'];
      this.info.checkNum = (this.info.progress.check == null || this.info.progress.check['done'] == null) ? "0" : this.info.progress.check['done'];
      this.info.authNum = (this.info.progress.quality == null || this.info.progress.quality['done'] == null) ? "0" : this.info.progress.quality['done'];
    },

    async loadHistory() {
      let { pageSize, currPage } = this.pagination
      let hisListInfo = await this.ass_api.exportHistory({ batchId: this.info.batchId, currPage: currPage, pageSize: pageSize })
      if (!hisListInfo) return;
      this.pagination.pageSize = hisListInfo.pageSize;
      this.historyList = hisListInfo.list;
    },
    history_open() {
      this.historyBox = true;
      this.loadHistory();
    },
    history_close() {
      this.historyBox = false;
      this.historyList = [];
    },
    download(id) {
      var fileName = encodeURI(encodeURI(this.info.batchName + "" + (new Date()).valueOf()));
      var iframe = document.getElementsByName("downloadBox")[0];
      if (iframe) {
        iframe.src = "/v1/exportData/getFile?id=" + id + "&fileName=" + fileName;
      } else {
        var newIframe = document.createElement("iframe");
        newIframe.name = "downloadBox";
        newIframe.src = "/v1/exportData/getFile?id=" + id + "&fileName=" + fileName;
        newIframe.style.display = "none";
        document.body.appendChild(newIframe);
      }
    },
    exporto() { //导出到研发网
      let custom = this.$refs.exportSet.$data
      this.info.step = custom.step;
      this.info.stamp = custom.stamp;
      if (this.info.endTime != '' && this.info.startTime != '') {
        var a = (Date.parse(this.info.endTime) - Date.parse(this.info.startTime)) / 3600 / 1000;
        if (a < 0) {
          this.ui.informModal(undefined, Lang.manage_js_export_time_tips_1);
          return;
        }
      } else if (this.info.endTime == 0 && this.info.startTime == '') {
        this.ui.informModal(undefined, Lang.manage_js_export_time_tips_2);
        return;
      }
      window.location.href = "/manager/index/batch/exportrdbom?batchid=" + this.info.batchId + '&taskid=' + this.info.taskId + '&batchName=' + this.info.batchName + '&step=' + this.info.step + '&stamp=' + this.info.stamp + '&endTime=' + this.info.endTime + '&startTime=' + this.info.startTime + '&fileCount=' + this.info.fileNum + '&taskName=' + this.info.taskName + '&groupId=' + this.groupId;
    },
    submit: function (msg) {
      console.log(this.info)
      return;
      let exportSet = this.$refs.exportSet
      let custom = exportSet.$data
      this.info.step = custom.step;
      this.info.stamp = custom.stamp;
      this.info.data = custom.data;
      if (this.info.endTime === '') {
        var nowTime = this.Utils.getNow();
        this.info.endTime = nowTime;
      }
      if (this.info.endTime != '' && this.info.startTime != '') {
        var a = (Date.parse(this.info.endTime) - Date.parse(this.info.startTime)) / 3600 / 1000;
        if (a < 0) {
          this.ui.informModal(undefined, Lang.manage_js_export_time_tips_1);
          return;
        }
      } else if (this.info.endTime == 0 && this.info.startTime == '') {
        this.ui.informModal(undefined, Lang.manage_js_export_time_tips_2);
        return;
      } else if (this.info.endTime == '') {
        this.ui.informModal(undefined, '请选择结束时间！');
        return;
      }
      if (exportSet.myvalidate() == 0) {
        if (this.info.batchId === '') {
          this.ui.informModal(undefined, Lang.manage_js_export_content_tips_1)
        }
        // var proxyurl = '/v1/be/task/batch/export?batchId=' + this.info.batchId + '&groupId=' + this.groupId;
        /*修复传参过大的问题*/
        var data = JSON.parse(JSON.stringify(this.info));
        var submitInfo = {
          batchId: data.batchId,
          startTime: data.startTime,
          endTime: data.endTime,
          stamp: data.stamp,
          step: data.step,
          taskId: data.taskId,
          data: data.data,
          batchName: data.batchName
        };
        /*修复传参过大的问题*/
        this.ass_api.exportPlay(submitInfo, {
          batchId: this.info.batchId,
          groupId: this.groupId
        }).then(data => {

          this.ui.fade(msg ? msg : Lang.manage_js_export_content_tips_2);
        })
      }
    },
    handleSizeChange(val) {
      this.loadHistory()
    },
    handleCurrentChange(val) {
      this.loadHistory()
    },
  },
  components: {
    ExportSet,
  },
  filters: {
    filterType(value) {
      if (value == '') {
        return Lang.default_all;
      } else if (value == '0') {
        return Lang.default_good_data;
      } else if (value == '1') {
        return Lang.default_bad_data;
      }
    },
    filterTime(value) {
      var date = new Date(value);
      var y = date.getFullYear();
      var m = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : ('0' + (date.getMonth() + 1));
      var d = (date.getDate()) > 9 ? date.getDate() : ('0' + (date.getDate()));
      var h = (date.getHours()) > 9 ? date.getHours() : ('0' + (date.getHours()));
      var min = (date.getMinutes()) > 9 ? date.getMinutes() : ('0' + (date.getMinutes()));
      var s = (date.getSeconds()) > 9 ? date.getSeconds() : ('0' + (date.getSeconds()));
      return y + "-" + m + "-" + d + " " + h + ":" + min + ":" + s;
    },
    filterStatus(value) {
      if (value == '0') {
        return Lang.js_filter_exporting;
      } else if (value == '1') {
        return Lang.js_filter_export_success;
      } else if (value == '-1') {
        return Lang.js_filter_exporting_fail;
      }
    }
  }
}
</script>

<style lang="less" scoped>
.export_wrapper {
  #pagebox {
    background: #fff;
    position: relative;
    overflow: hidden;
  }
  .talent_detail {
    padding: 0 20px 20px;
    min-height: 769px;
  }
  .fs16_bold {
    font-size: 16px;
    font-weight: 700;
  }
  .fs14_bold {
    font-size: 14px;
    font-weight: 700;
  }
  var {
    font-style: normal;
  }
  .exprot_his {
    .title {
      line-height: 58px;
      padding-left: 15px;
      position: relative;
      height: 58px;
      border-bottom: 1px solid #ececec;
      color: #5e6a68;
      &::before {
        content: "";
        display: block;
        height: 14px;
        width: 4px;
        background: #14cb6b;
        position: absolute;
        left: 0;
        top: 21px;
      }
      a {
        float: right;
        width: 110px;
        height: 34px;
        border: 1px solid #fcad1d;
        color: #fcad1d;
        background: #fff;
        -webkit-border-radius: 2px;
        -moz-border-radius: 2px;
        -ms-border-radius: 2px;
        -o-border-radius: 2px;
        border-radius: 2px;
        font-weight: normal;
        font-size: 14px;
        line-height: 32px;
        padding-left: 25px;
        text-align: center;
        position: relative;
        margin-top: 12px;
      }
      a:before {
        position: absolute;
        width: 17px;
        height: 15px;
        display: block;
        content: "";
        background: url("~@/assets/images/common/work-team/history_ico.png")
          no-repeat 0 0;
        left: 15px;
        top: 10px;
      }
    }
  }
  .info {
    height: 50px;
    line-height: 50px;
    font-size: 14px;
    color: #333;
    background: #f9f9f9;
    margin-top: 10px;
    span {
      padding: 0 50px 0 20px;
    }
    span.sp-1 {
      width: 320px;
      display: inline-block;
      height: 14px;
      line-height: 14px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
  .typelist {
    margin-top: 23px;
    position: relative;
    .freetime {
      position: absolute;
      bottom: 0;
      left: 530px;
      input {
        width: 137px;
        height: 30px;
        line-height: 30px;
        padding: 0 30px 0 10px;
        border: 1px solid #e0e0e0;
        -webkit-border-radius: 2px;
        -moz-border-radius: 2px;
        -ms-border-radius: 2px;
        -o-border-radius: 2px;
        border-radius: 2px;
        background: url("~@/assets/images/common/work-team/time_ico.png")
          no-repeat 111px 4px;
      }
      span {
        padding: 0 10px;
        line-height: 30px;
      }
    }
  }
  .selectBox {
    padding: 0;
    position: relative;
    .typeli {
      line-height: 36px;
      height: 36px;
      font-size: 0;
      color: #666;
      margin-bottom: 14px;
    }
    .typeli:last-of-type {
      border: 0;
    }
  }
  .typeli span {
    font-size: 14px;
    float: left;
    line-height: 36px;
    margin-right: 11px;
  }
  .typeli a {
    width: 100px;
    display: inline-block;
    font-size: 14px;
    margin-right: 11px;
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    -ms-border-radius: 2px;
    -o-border-radius: 2px;
    border-radius: 2px;
    height: 36px;
    line-height: 34px;
    color: #666;
    text-align: center;
    border: 1px solid #e0e0e0;
    float: left;
    cursor: pointer;
  }
  .typeli a.select {
    color: #14cb6b;
    border: 1px solid #14cb6b;
    background: #dbfceb;
    position: relative;
  }
  .typeli a.select:after {
    position: absolute;
    width: 22px;
    height: 22px;
    display: block;
    content: "";
    background: url("~@/assets/images/common/work-team/task_select_ico.png")
      no-repeat 0 0;
    right: 0px;
    bottom: 0px;
  }
  .export_btn {
    font-size: 0;
    text-align: center;
    padding-bottom: 24px;
    margin-top: 100px;
    a {
      display: inline-block;
      width: 120px;
      height: 34px;
      text-align: center;
      line-height: 34px;
      color: #fff;
      border: 1px solid #fcad1d;
      -webkit-border-radius: 2px;
      -moz-border-radius: 2px;
      -ms-border-radius: 2px;
      -o-border-radius: 2px;
      border-radius: 2px;
      font-size: 14px;
      cursor: pointer;
      background: #fcad1d;
      margin-right: 12px;
    }
    a:hover {
      border: 1px solid #e07900;
      background: #e07900;
    }
  }

  .layer {
    background: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    left: 0;
    top: 0;
  }
  .show_pop.history {
    width: 900px;
    max-height: 560px;
    margin-left: -450px;
    margin-top: -280px;
    overflow-y: scroll;
  }
  .show_pop {
    width: 405px;
    text-align: left;
    display: block;
    position: fixed;
    left: 50%;
    margin-left: -202px;
    top: 50%;
    margin-top: -119px;
    background: #fff;
    overflow: hidden;
    .poptitle {
      line-height: 40px;
      height: 40px;
      border-bottom: 1px solid #e5e5e5;
      background: #f5f5f5;
    }
    .poptitle i {
      float: right;
      width: 12px;
      height: 12px;
      display: block;
      background: url("~@/assets/images/common//close.png") no-repeat 0 0;
      margin-top: 14px;
      margin-right: 20px;
      cursor: pointer;
    }
    .poptitle span {
      padding-left: 20px;
    }
    .popdis {
      text-align: center;
      line-height: 30px;
      padding: 24px 0;
    }
  }
  .table {
    padding: 20px;
    text-align: center;
    table {
      border-right: 1px solid #ececec;
      border-collapse: collapse;
    }
    thead {
      background: #f5f5f5;
    }
    thead td {
      color: #666;
    }
    tr td {
      font-size: 14px;
      height: 45px;
      word-break: break-all;
      padding: 0 5px;
      line-height: initial;
    }
    td {
      border-right: 0;
      border: 1px solid #ececec;
    }
    td a {
      color: #14cb6b;
      cursor: pointer;
    }
  }
}
</style>
<style lang="less">
.export_wrapper {
  .page_nav {
    padding: 0 20px 20px 20px;
  }
}
</style>

